import datetime
import re

from Wallpaper.models import Wallpaper


def main():
    wallpaper_list = Wallpaper.objects.all().filter(create_time=None)
    for item in wallpaper_list:
        print(item.url)
        match = re.search(r"/(\d{4})/(\d{2})(\d{2})/", item.url)
        year, mouth, day = match.group(1), match.group(2), match.group(3)
        print(match.group(), year, mouth, day, sep="\n")
        dt = datetime.datetime(year=int(year), month=int(mouth), day=int(day))
        try:
            item.create_time = dt
            item.save()
        except:
            print(item.url)
            print("error")


if __name__ == "__main__":
    main()
